package com.jeff.tianti.controller;

import com.jeff.tianti.cms.dto.*;
import com.jeff.tianti.cms.entity.*;
import com.jeff.tianti.cms.service.*;
import com.jeff.tianti.common.dto.AjaxResult;
import com.jeff.tianti.common.entity.PageModel;
import com.jeff.tianti.org.service.UserService;
import com.jeff.tianti.util.Constants;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.record.PasswordRev4Record;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@RequestMapping("/information")
@Controller
public class InformationController {
    @Autowired
    private UserService userService;
    @Autowired
    private MessageInteractionService messageInteractionService;

    /**
     * @Ceator:liuYI
     * @Describe:互动留言列表
     */
    @RequestMapping("/theInteractiveMessage")
    public String theInteractiveMessage(HttpServletRequest request, Model model) {
//        MessageInteraction
        String currentPageStr = request.getParameter("currentPage");//当前页
        String pageSizeStr = request.getParameter("pageSize");//每页显示条数
        String auditFlag = request.getParameter("auditFlag");//是否处理0->未处理 1->处理
        int currentPage = 1;
        int pageSize = 10;
        if (StringUtils.isNotBlank(currentPageStr)) {
            currentPage = Integer.parseInt(currentPageStr);
        }
        if (StringUtils.isNotBlank(pageSizeStr)) {
            pageSize = Integer.parseInt(pageSizeStr);
        }
        MessageInteractionQueryDTO messageInteractionQueryDTO = new MessageInteractionQueryDTO();
        messageInteractionQueryDTO.setPageSize(pageSize);
        messageInteractionQueryDTO.setCurrentPage(currentPage);
        messageInteractionQueryDTO.setAuditFlag(auditFlag);
        PageModel<MessageInteraction> page = messageInteractionService.queryMessageInteractionPage(messageInteractionQueryDTO);
        model.addAttribute("page", page);
        model.addAttribute("messageInteractionQueryDTO", messageInteractionQueryDTO);
        model.addAttribute("pageSize", pageSize);
        model.addAttribute(Constants.MENU_NAME, Constants.THE_INTERACTIVE_MESSAGE);
        return "user/information/the_interactive_message";
    }

    /**
     * @Ceator:liuYI
     * @Describe:互动留言详情查看
     */
    @RequestMapping("/theInteractiveMessage/edit")
    public String findTheInteractiveMessageById(HttpServletRequest request, Model model) {
        String id = request.getParameter("id");
        MessageInteraction messageInteraction = new MessageInteraction();
        if (StringUtils.isNotBlank(id)) {
            messageInteraction = messageInteractionService.find(id);
        }
        model.addAttribute(Constants.MENU_NAME, Constants.THE_INTERACTIVE_MESSAGE);
        model.addAttribute("messageInteraction", messageInteraction);
        return "user/information/edit/the_interactive_message_edit";
    }

    /**
     * @Ceator:liuYI
     * @Describe:互动留言处理操作
     */
    @RequestMapping("/theInteractiveMessage/auditFlag")
    @ResponseBody
    public AjaxResult theInteractiveMessageAuditFlag(HttpServletRequest request) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);
        try {
            String id = request.getParameter("id");
            if (StringUtils.isNotBlank(id)) {
                String[] split = id.split(",");
                List<String> list = Arrays.asList(split);
                list.forEach(t -> {
                    MessageInteraction messageInteraction = messageInteractionService.find(t);
                    messageInteraction.setAuditFlag("1");
                    messageInteractionService.update(messageInteraction);
                });
            }
            ajaxResult.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ajaxResult;
    }

    @Autowired
    private ReportService reportService;

    /**
     * @Ceator:liuYI
     * @Describe:违法举报列表
     */
    @RequestMapping("/illegalTooReport")
    public String illegalTooReport(HttpServletRequest request, Model model) {
//        Report
        //        MessageInteraction
        String currentPageStr = request.getParameter("currentPage");//当前页
        String pageSizeStr = request.getParameter("pageSize");//每页显示条数
        String auditFlag = request.getParameter("auditFlag");//是否处理0->未处理 1->处理
        int currentPage = 1;
        int pageSize = 10;
        if (StringUtils.isNotBlank(currentPageStr)) {
            currentPage = Integer.parseInt(currentPageStr);
        }
        if (StringUtils.isNotBlank(pageSizeStr)) {
            pageSize = Integer.parseInt(pageSizeStr);
        }
        ReportQueryDTO reportQueryDTO = new ReportQueryDTO();
        reportQueryDTO.setPageSize(pageSize);
        reportQueryDTO.setCurrentPage(currentPage);
        reportQueryDTO.setAuditFlag(auditFlag);
        PageModel<Report> page = reportService.queryReportPage(reportQueryDTO);
        model.addAttribute(Constants.MENU_NAME, Constants.ILLEGAL_TO_REPORT);
        model.addAttribute("page", page);
        model.addAttribute("pageSize", pageSize);
        model.addAttribute("reportQueryDTO", reportQueryDTO);
        return "user/information/illegal_to_report";
    }

    /**
     * @Ceator:liuYI
     * @Describe:违法举报详情查看
     */
    @RequestMapping("/illegalTooReport/edit")
    public String findIllegalTooReportById(HttpServletRequest request, Model model) {
        String id = request.getParameter("id");
        Report report = new Report();
        if (StringUtils.isNotBlank(id)) {
            report = reportService.find(id);

        }
        model.addAttribute("report", report);
        model.addAttribute(Constants.MENU_NAME, Constants.ILLEGAL_TO_REPORT);
        return "user/information/edit/illegal_to_report_edit";
    }

    /**
     * @Ceator:liuYI
     * @Describe:违法举报处理操作
     */
    @RequestMapping("/illegalTooReport/auditFlag")
    @ResponseBody
    public AjaxResult illegalTooReportAuditFlag(HttpServletRequest request) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);
        try {
            String id = request.getParameter("id");
            String auditFlag = request.getParameter("auditFlag");//是否处理0->未处理 1->处理
            if (StringUtils.isNotBlank(id)) {
                Arrays.stream(id.split(",")).forEach(t -> {
                    Report report = reportService.find(t);
                    report.setAuditFlag("1");
                    reportService.update(report);
                });
            }
            ajaxResult.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ajaxResult;
    }


    @Autowired
    private CourseCounselService courseCounselService;

    /**
     * @Ceator:liuYI
     * @Describe:培训报名列表
     */
    @RequestMapping("/trainingRegistration")
    public String trainingRegistration(HttpServletRequest request, Model model) {
        String currentPageStr = request.getParameter("currentPage");//当前页
        String pageSizeStr = request.getParameter("pageSize");//每页显示条数
        String state = request.getParameter("state");//状态
        int currentPage = 1;
        int pageSize = 10;
        if (StringUtils.isNotBlank(currentPageStr)) {
            currentPage = Integer.parseInt(currentPageStr);
        }
        if (StringUtils.isNotBlank(pageSizeStr)) {
            pageSize = Integer.parseInt(pageSizeStr);
        }
        CourseCounselQueryDTO courseCounselQueryDTO = new CourseCounselQueryDTO();
        courseCounselQueryDTO.setPageSize(pageSize);
        courseCounselQueryDTO.setCurrentPage(currentPage);
        courseCounselQueryDTO.setState(state);
        PageModel<CourseCounsel> page = courseCounselService.queryCourseCounselPage(courseCounselQueryDTO);
        model.addAttribute("page", page);
        model.addAttribute("courseCounselQueryDTO", courseCounselQueryDTO);
        model.addAttribute("pageSize", pageSize);
        model.addAttribute("courseCounselQueryDTO", courseCounselQueryDTO);
        model.addAttribute(Constants.MENU_NAME, Constants.TRAINING_REGISTRATION);
//CourseCounsel
        return "user/information/training_registration";
    }

    /**
     * @Ceator:liuYI
     * @Describe:培训报名详情
     */
    @RequestMapping("/trainingRegistration/edit")
    public String findTrainingRegistrationById(HttpServletRequest request, Model model) {
        String id = request.getParameter("id");
        CourseCounsel courseCounsel = new CourseCounsel();
        if (StringUtils.isNotBlank(id)) {
            courseCounsel = courseCounselService.find(id);
        }
        model.addAttribute("courseCounsel", courseCounsel);
        model.addAttribute(Constants.MENU_NAME, Constants.TRAINING_REGISTRATION);
        return "user/information/edit/training_registration_edit";
    }

    /**
     * @Ceator:liuYI
     * @Describe:培训报名回复
     */
    @RequestMapping("/trainingRegistration/reply")
    @ResponseBody
    public AjaxResult trainingRegistrationReply(HttpServletRequest request) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);
        try {
            String id = request.getParameter("id");
            String text = request.getParameter("text");
            if (StringUtils.isNotBlank(id)) {
                CourseCounsel courseCounsel = courseCounselService.find(id);
                courseCounsel.setReply(text);
                courseCounsel.setReplyDate(new Date());
                courseCounsel.setState("1");
                courseCounselService.update(courseCounsel);
            }
            ajaxResult.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ajaxResult;
    }

    @Autowired
    private JobService jobService;

    /**
     * @Ceator:liuYI
     * @Describe:招聘信息列表
     */
    @RequestMapping("/recruitmentInformation")
    public String recruitmentInformation(HttpServletRequest request, Model model) {
        String currentPageStr = request.getParameter("currentPage");//当前页
        String pageSizeStr = request.getParameter("pageSize");//每页显示条数
        String sortNum = request.getParameter("createDate");//时间   asc 升序   desc 降序
        String publishType = request.getParameter("publishType");//发布类型   0-兼职  1-全职
        String auditFlag = request.getParameter("auditFlag");//审核状态 0-待审核  1审核通过  2审核不通过
        String jobName = request.getParameter("jobName");//职位名称
        int currentPage = 1;
        int pageSize = 10;
        if (StringUtils.isNotBlank(currentPageStr)) {
            currentPage = Integer.parseInt(currentPageStr);
        }
        if (StringUtils.isNotBlank(pageSizeStr)) {
            pageSize = Integer.parseInt(pageSizeStr);
        }
        JobQueryDTO jobQueryDTO = new JobQueryDTO();
        jobQueryDTO.setCurrentPage(currentPage);
        jobQueryDTO.setPageSize(pageSize);
        jobQueryDTO.setSortNum(sortNum);
        jobQueryDTO.setPublishType(publishType);
        jobQueryDTO.setAuditFlag(auditFlag);
        jobQueryDTO.setJobName(jobName);
        PageModel<Job> page = jobService.queryJobPage(jobQueryDTO);
//    educational_requirements    学历要求 0->不限 1->高中 2->技校 3->中专 4->大专 5->本科 6->硕士 7->博士
//  work_experience     工作经验  0->不限  1->一年以下 2->1-2年 3->3-5年 4->6-7年 5->8-10年 6->10-15年 7->15年以上
        page.getList().stream().forEach(t -> {
            t.setWorkExperience(jobWorkExperience(t.getWorkExperience()));
            t.setEducationalRequirements(jobEducationalRequirements(t.getEducationalRequirements()));
        });
        model.addAttribute("page", page);
        model.addAttribute("pageSize", pageSize);
        model.addAttribute(Constants.MENU_NAME, Constants.RECRUITMENT_INFORMATION);
        model.addAttribute("jobQueryDTO", jobQueryDTO);
        return "user/information/recruitment_information";
    }

    public String jobWorkExperience(String s) {
        return "0".equals(s) ? "不限" : "1".equals(s) ? "一年以下" : "2".equals(s) ? "1-2年" : "3".equals(s) ? "3-5年" : "4".equals(s) ? "6-7年" : "5".equals(s) ? "8-10年" : "6".equals(s) ? "10-15年" : "7".equals(s) ? "15年以上" : "";
    }

    public String jobEducationalRequirements(String s) {
        return "0".equals(s) ? "不限" : "1".equals(s) ? "高中" : "2".equals(s) ? "技校" : "3".equals(s) ? "中专" : "4".equals(s) ? "大专" : "5".equals(s) ? "本科" : "6".equals(s) ? "硕士" : "7".equals(s) ? "博士" : "";
    }

    /**
     * @Ceator:liuYI
     * @Describe:招聘信息审核
     */
    @RequestMapping("/recruitmentInformation/update")
    @ResponseBody
    public AjaxResult updateRecruitmentInformationState(HttpServletRequest request) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);
        try {
            String auditFlag = request.getParameter("auditFlag");
            String id = request.getParameter("id");
            if (StringUtils.isNotBlank(id) && StringUtils.isNotBlank(auditFlag)) {
                Job job = jobService.find(id);
                String uid = job.getUid();
                Boolean bool = true;
                if ("2".equals(auditFlag)) {
                    bool = companyService.findByUid(uid);
                    if (!bool) {
                        ajaxResult.setMsg("发布招聘岗位的公司信息，还未被审核通过");
                        return ajaxResult;
                    }
                }
                if (bool) {
                    job.setAuditFlag(auditFlag);
                    jobService.update(job);
                }
            }
            ajaxResult.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ajaxResult;
    }

    /**
     * @Ceator:liuYI
     * @Describe:招聘信息详情预览
     */
    @RequestMapping("/recruitmentInformation/edit")
    public String finRecruitmentInformationById(HttpServletRequest request, Model model) {
        Job job = null;
        String id = request.getParameter("id");
        if (StringUtils.isNotBlank(id)) {
            job = jobService.find(id);
        }
        model.addAttribute("job", job);
        model.addAttribute(Constants.MENU_NAME, Constants.RECRUITMENT_INFORMATION);
        return "user/information/edit/recruitment_information_edit";
    }

    @Autowired
    private ResumeService resumeService;

    /**
     * @Ceator:liuYI
     * @Describe:人才信息列表
     */
    @RequestMapping("/personnelInformation")
    public String personnelInformation(HttpServletRequest request, Model model) {
        String currentPageStr = request.getParameter("currentPage");//当前页
        String pageSizeStr = request.getParameter("pageSize");//每页显示条数
        String sortNum = request.getParameter("createDate");//时间   asc 升序   desc 降序
        String jobName = request.getParameter("jobName");//职位名称
        int currentPage = 1;
        int pageSize = 10;
        if (StringUtils.isNotBlank(currentPageStr)) {
            currentPage = Integer.parseInt(currentPageStr);
        }
        if (StringUtils.isNotBlank(pageSizeStr)) {
            pageSize = Integer.parseInt(pageSizeStr);
        }
        ResumeQueryDTO resumeQueryDTO = new ResumeQueryDTO();
        resumeQueryDTO.setCurrentPage(currentPage);
        resumeQueryDTO.setPageSize(pageSize);
        resumeQueryDTO.setJobName(jobName);
        resumeQueryDTO.setSortNum(sortNum);
        PageModel<Resume> page = resumeService.queryResumePage(resumeQueryDTO);
        page.getList().stream().forEach(t -> {
            t.setWorkExperience(switchWorkExperience(t.getWorkExperience()));
            t.setEducationBackground(switchEducationBackground(t.getEducationBackground()));
        });
        model.addAttribute("page", page);
        model.addAttribute("pageSize", pageSize);
        model.addAttribute("resumeQueryDTO", resumeQueryDTO);
        model.addAttribute(Constants.MENU_NAME, Constants.PERSONNEL_INFORMATION);
        return "user/information/personnel_information";
    }

    public String switchEducationBackground(String educationBackground) {
        if (StringUtils.isBlank(educationBackground)) {
            return "";
        }
        //        学历要求 0->高中 1->技校 2->中专 3->大专 4->本科 5->硕士 6->博士
        switch (educationBackground) {
            case "0":
                return "高中";
            case "1":
                return "技校";
            case "2":
                return "中专";
            case "3":
                return "大专";
            case "4":
                return "本科";
            case "5":
                return "硕士";
            case "6":
                return "博士";
            default:
                return "";
        }
    }

    public String switchWorkExperience(String workExperience) {
        if (StringUtils.isBlank(workExperience)) {
            return "";
        }
//        工作经验 工作经验  0->1年以下 1->1-2年 2->3-5年 3->6-7年 4->8-10年 5->10-15年 6->15年以上
        switch (workExperience) {
            case "0":
                return "1年以下";
            case "1":
                return "1-2年";
            case "2":
                return "3-5年";
            case "3":
                return "6-7年";
            case "4":
                return "8-10年";
            case "5":
                return "10-15年";
            case "6":
                return "15年以上";
            default:
                return "";
        }
    }

    /**
     * @Ceator:liuYI
     * @Describe:人才列表详情展示
     */
    @RequestMapping("/personnelInformation/edit")
    public String findPersonnelInformationById(HttpServletRequest request, Model model) {
        Resume resume = null;
        String id = request.getParameter("id");
        if (StringUtils.isNotBlank(id)) {
            resume = resumeService.find(id);
            resume.setWorkExperience(switchWorkExperience(resume.getWorkExperience()));
            resume.setEducationBackground(switchEducationBackground(resume.getEducationBackground()));
        }
        model.addAttribute("resume", resume);
        model.addAttribute(Constants.MENU_NAME, Constants.PERSONNEL_INFORMATION);
        return "user/information/edit/personnel_information_edit";
    }

    @Autowired
    private ApplicationForMembershipService applicationService;

    /**
     * @Ceator:liuYI
     * @Describe:入会申请列表
     */
    @RequestMapping("/applicationForMembership")
    public String applicationForMembership(HttpServletRequest request, Model model) {
        String currentPageStr = request.getParameter("currentPage");//当前页
        String pageSizeStr = request.getParameter("pageSize");//每页显示条数
        String auditFlag = request.getParameter("auditFlag");//每页显示条数
        int currentPage = 1;
        int pageSize = 10;
        if (StringUtils.isNotBlank(currentPageStr)) {
            currentPage = Integer.parseInt(currentPageStr);
        }
        if (StringUtils.isNotBlank(pageSizeStr)) {
            pageSize = Integer.parseInt(pageSizeStr);
        }
        ApplicationForMembershipQueryDTO applicationDTO = new ApplicationForMembershipQueryDTO();
        applicationDTO.setCurrentPage(currentPage);
        applicationDTO.setPageSize(pageSize);
        applicationDTO.setAuditFlag(auditFlag);
        PageModel<ApplicationForMembership> page = applicationService.queryApplicationForMembershipPage(applicationDTO);
        model.addAttribute("page", page);
        model.addAttribute("applicationDTO", applicationDTO);
        model.addAttribute("pageSize", pageSize);
        model.addAttribute(Constants.MENU_NAME, Constants.APPLICATION_FOR_MEMBERSHIP);
        return "user/information/application_for_membership";
    }

    /**
     * @Ceator:liuYI
     * @Describe:入会申请详情预览
     */
    @RequestMapping("/applicationForMembership/edit")
    public String findApplicationForMembershipById(HttpServletRequest request, Model model) {
        String id = request.getParameter("id");
        ApplicationForMembership applicationForMembership = new ApplicationForMembership();
        if (StringUtils.isNotBlank(id)) {
            applicationForMembership = applicationService.find(id);
        }
        model.addAttribute("application", applicationForMembership);
        model.addAttribute(Constants.MENU_NAME, Constants.APPLICATION_FOR_MEMBERSHIP);
        return "user/information/edit/application_for_membership_edit";
    }

    /**
     * @Ceator:liuYI
     * @Describe:入会申请处理操作
     */
    @RequestMapping("/applicationForMembership/audit_flag")
    @ResponseBody
    public AjaxResult updateApplicationForMembership(HttpServletRequest request, Model model) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);
        try {
            String id = request.getParameter("id");
            if (StringUtils.isNotBlank(id)) {
                String[] split = id.split(",");
                Arrays.stream(split).forEach(t -> {
                    ApplicationForMembership applicationForMembership = applicationService.find(t);
                    applicationForMembership.setAuditFlag("1");
                    applicationService.update(applicationForMembership);
                });
            }
            ajaxResult.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ajaxResult;
    }

    @Autowired
    private ConsultService consultService;
    @Autowired
    private ConsultComplianceService consultComplianceService;

    /**
     * @Ceator:liuYI
     * @Describe:合规资询列表展示
     */
    @RequestMapping("/complianceConsulting")
    public String complianceConsulting(HttpServletRequest request, Model model) {
        String currentPageStr = request.getParameter("currentPage");//当前页
        String pageSizeStr = request.getParameter("pageSize");//每页显示条数
        String state = request.getParameter("state");//状态:0->资询中 1->已完成
        int currentPage = 1;
        int pageSize = 10;
        if (StringUtils.isNotBlank(currentPageStr)) {
            currentPage = Integer.parseInt(currentPageStr);
        }
        if (StringUtils.isNotBlank(pageSizeStr)) {
            pageSize = Integer.parseInt(pageSizeStr);
        }
        ConsultComplianceQueryDTO consultComplianceQueryDTO = new ConsultComplianceQueryDTO();
        consultComplianceQueryDTO.setPageSize(pageSize);
        consultComplianceQueryDTO.setCurrentPage(currentPage);
        consultComplianceQueryDTO.setState(state);
        PageModel<ConsultCompliance> page = consultComplianceService.queryConsultCompliancePage(consultComplianceQueryDTO);
        model.addAttribute("page", page);
        model.addAttribute("pageSize", pageSize);
        model.addAttribute("consultComplianceQueryDTO", consultComplianceQueryDTO);
        model.addAttribute(Constants.MENU_NAME, Constants.COMPLIANCE_CONSULTING);
        return "user/information/compliance_consulting";
    }

    /**
     * @Ceator:liuYI
     * @Describe:合规资询详情展示
     */
    @RequestMapping("/complianceConsulting/edit")
    public String findComplianceConsultingById(HttpServletRequest request, Model model) {
        String id = request.getParameter("id");
        ConsultCompliance consultCompliance = null;
        if (StringUtils.isNotBlank(id)) {
            consultCompliance = consultComplianceService.find(id);
        }
        model.addAttribute("consultCompliance", consultCompliance);
        model.addAttribute(Constants.MENU_NAME, Constants.COMPLIANCE_CONSULTING);
        return "user/information/edit/compliance_consulting_edit";
    }

    /**
     * @Ceator:liuYI
     * @Describe:合规资询回复
     */
    @RequestMapping("/complianceConsulting/reply")
    @ResponseBody
    public AjaxResult ComplianceConsultingReply(HttpServletRequest request) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);
        try {
            String id = request.getParameter("id");
            String text = request.getParameter("text");
            if (StringUtils.isNotBlank(id)) {
                ConsultCompliance consultCompliance = consultComplianceService.find(id);
                consultCompliance.setReply(text);
                consultCompliance.setReplyDate(new Date());
                consultCompliance.setState("1");
                consultComplianceService.update(consultCompliance);
            }
            ajaxResult.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ajaxResult;
    }

    /**
     * @Ceator:liuYI
     * @Describe:知识产权资询列表
     */
    @RequestMapping("/intellectualProperty")
    public String intellectualProperty(HttpServletRequest request, Model model) {
        String currentPageStr = request.getParameter("currentPage");//当前页
        String pageSizeStr = request.getParameter("pageSize");//每页显示条数
        String state = request.getParameter("state");//状态
        int currentPage = 1;
        int pageSize = 10;
        if (StringUtils.isNotBlank(currentPageStr)) {
            currentPage = Integer.parseInt(currentPageStr);
        }
        if (StringUtils.isNotBlank(pageSizeStr)) {
            pageSize = Integer.parseInt(pageSizeStr);
        }
        ConsultQueryDTO consultQueryDTO = new ConsultQueryDTO();
        consultQueryDTO.setCurrentPage(currentPage);
        consultQueryDTO.setPageSize(pageSize);
        consultQueryDTO.setState(state);
        PageModel<Consult> page = consultService.queryConsultPage(consultQueryDTO);
        model.addAttribute("page", page);
        model.addAttribute("pageSize", pageSize);
        model.addAttribute("consultQueryDTO", consultQueryDTO);
        model.addAttribute(Constants.MENU_NAME, Constants.INTELLECTUAL_PROPERTY);

        return "user/information/intellectual_property";
    }

    /**
     * @Ceator:liuYI
     * @Describe:知识产权资询详情展示
     */
    @RequestMapping("/intellectualProperty/edit")
    public String findIntellectualPropertyById(HttpServletRequest request, Model model) {
        Consult consult = null;
        String id = request.getParameter("id");
        if (StringUtils.isNotBlank(id)) {
            consult = consultService.find(id);
        }
        model.addAttribute("consult", consult);
        model.addAttribute(Constants.MENU_NAME, Constants.COMPLIANCE_CONSULTING);
        return "user/information/edit/intellectual_property_edit";
    }

    /**
     * @Ceator:liuYI
     * @Describe:知识产权问题回复
     */
    @RequestMapping("/intellectualProperty/reply")
    @ResponseBody
    public AjaxResult intellectualPropertyReply(HttpServletRequest request) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);
        try {
            String id = request.getParameter("id");
            String text = request.getParameter("text");
            if (StringUtils.isNotBlank(id)) {
                Consult consult = consultService.find(id);
                consult.setReply(text);
                consult.setReplyDate(new Date());
                consult.setState("1");
                consultService.update(consult);
            }
            ajaxResult.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return ajaxResult;
    }

    @Autowired
    private AwardsToDeclareService awardsToDeclareService;

    /**
     * @Ceator:liuYI
     * @Describe:奖项申报列表
     */
    @RequestMapping("/awardsToDeclare")
    public String awardsToDeclare(HttpServletRequest request, Model model) {
//        AwardsToDeclareTo
        String currentPageStr = request.getParameter("currentPage");//当前页
        String pageSizeStr = request.getParameter("pageSize");//每页显示条数
        String auditFlag = request.getParameter("auditFlag");//是否处理0->未处理 1->处理
        int currentPage = 1;
        int pageSize = 10;
        if (StringUtils.isNotBlank(currentPageStr)) {
            currentPage = Integer.parseInt(currentPageStr);
        }
        if (StringUtils.isNotBlank(pageSizeStr)) {
            pageSize = Integer.parseInt(pageSizeStr);
        }
        AwardsToDeclareQueryDTO awardsToDeclareQueryDTO = new AwardsToDeclareQueryDTO();
        awardsToDeclareQueryDTO.setPageSize(pageSize);
        awardsToDeclareQueryDTO.setCurrentPage(currentPage);
        awardsToDeclareQueryDTO.setAuditFlag(auditFlag);
        PageModel<AwardsToDeclare> page = awardsToDeclareService.queryAwardsToDeclarePage(awardsToDeclareQueryDTO);
        model.addAttribute("page", page);
        model.addAttribute("pageSize", pageSize);
        model.addAttribute("awardsToDeclareQueryDTO", awardsToDeclareQueryDTO);
        model.addAttribute(Constants.MENU_NAME, Constants.AWARDS_TO_DECLARE);
        return "user/information/awards_to_declare";
    }

    /**
     * @Ceator:liuYI
     * @Describe:奖项申报处理操作
     */
    @RequestMapping("/awardsToDeclare/auditFlag")
    @ResponseBody
    public AjaxResult awardsToDeclareAuditFlag(HttpServletRequest request, Model model) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);
        try {
            String id = request.getParameter("id");
            if (StringUtils.isNotBlank(id)) {
                Arrays.stream(id.split(",")).forEach(t -> {
                    AwardsToDeclare awardsToDeclare = awardsToDeclareService.find(t);
                    awardsToDeclare.setAuditFlag("1");
                    awardsToDeclareService.update(awardsToDeclare);
                });
            }
            ajaxResult.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ajaxResult;
    }

    /**
     * @Ceator:liuYI
     * @Describe:奖项申报详情查看
     */
    @RequestMapping("/awardsToDeclare/edit")
    public String findAwardsToDeclareById(HttpServletRequest request, Model model) {
        String id = request.getParameter("id");
        AwardsToDeclare awardsToDeclare = new AwardsToDeclare();
        if (StringUtils.isNotBlank(id)) {
            awardsToDeclare = awardsToDeclareService.find(id);
        }
        model.addAttribute("awardsToDeclare", awardsToDeclare);
        model.addAttribute(Constants.MENU_NAME, Constants.AWARDS_TO_DECLARE);
        return "user/information/edit/awards_to_declare_edit";
    }

    @Autowired
    private QuestionsAnswersService questionsAnswersService;
    @Autowired
    private AnswersService answersService;

    /**
     * @Ceator:liuYI
     * @Describe:问答管理列表
     */
    @RequestMapping("/management")
    public String management(HttpServletRequest request, Model model) {
//        QuestionsAnswers
        String currentPageStr = request.getParameter("currentPage");//当前页
        String pageSizeStr = request.getParameter("pageSize");//每页显示条数
        String state = request.getParameter("state");//状态0->资询中 1->已完成
        String auditFlag = request.getParameter("auditFlag");//审核字段 0->待审核 1->审核不通过 2审核通过
        String questionsAndAnswers = request.getParameter("questionsAndAnswers");//问答字段 0->答 1->问
        int currentPage = 1;
        int pageSize = 10;
        if (StringUtils.isNotBlank(currentPageStr)) {
            currentPage = Integer.parseInt(currentPageStr);
        }
        if (StringUtils.isNotBlank(pageSizeStr)) {
            pageSize = Integer.parseInt(pageSizeStr);
        }
        QuestionsAnswersQueryDTO questionsAnswersQueryDTO = new QuestionsAnswersQueryDTO();
        questionsAnswersQueryDTO.setCurrentPage(currentPage);
        questionsAnswersQueryDTO.setPageSize(pageSize);
        questionsAnswersQueryDTO.setState(state);
        questionsAnswersQueryDTO.setAuditFlag(auditFlag);
        questionsAnswersQueryDTO.setQuestionsAndAnswers(questionsAndAnswers);
        Object page = null;
        if (QuestionsAnswersQueryDTO.QUESTIONS_NUM.equals(questionsAndAnswers)) {
            page = answersService.queryAnswersPages(questionsAnswersQueryDTO);
        } else {
            page = questionsAnswersService.queryQuestionsAnswersPage(questionsAnswersQueryDTO);
        }
        model.addAttribute("page", page);
        model.addAttribute("pageSize", pageSize);
        model.addAttribute("questionsAnswersQueryDTO", questionsAnswersQueryDTO);
        model.addAttribute("questionsAndAnswers", questionsAndAnswers);
        model.addAttribute(Constants.MENU_NAME, Constants.MANAGEMENT);
        return "user/information/management";
    }

    /**
     * @Ceator:liuYI
     * @Describe:问答管理审核
     */
    @RequestMapping("/management/audit_flag")
    @ResponseBody
    public AjaxResult updateAuditFlag(HttpServletRequest request, Model model) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);
        try {
            String id = request.getParameter("id");
            String auditFlag = request.getParameter("auditFlag");//审核字段 0->待审核 1->审核不通过 2审核通过
            String questionsAndAnswers = request.getParameter("questionsAndAnswers");//问答字段 0->答 1->问
            if (StringUtils.isNotBlank(id)) {
                if (QuestionsAnswersQueryDTO.QUESTIONS_NUM.equals(questionsAndAnswers)) {
                    Answers answers = answersService.find(id);
                    answers.setAuditFlag(auditFlag);
                    answersService.update(answers);
                } else {
                    QuestionsAnswers questionsAnswers = questionsAnswersService.find(id);
                    if (StringUtils.isNotBlank(auditFlag)) {
                        questionsAnswers.setAuditFlag(auditFlag);
                        if ("2".equals(auditFlag)) {//审核通过
                            questionsAnswers.setState("0");//设置回复状态为待回复
                        }
                        questionsAnswersService.update(questionsAnswers);
                    }
                }
            }
            ajaxResult.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ajaxResult;
    }

    /**
     * @Ceator:liuYI
     * @Describe:问答管理详情查看
     */
    @RequestMapping("/management/edit")
    public String findManagementById(HttpServletRequest request, Model model) {
        Object o = null;
        String id = request.getParameter("id");
        String questionsAndAnswers = request.getParameter("questionsAndAnswers");//问答字段 0->答 1->问
        if (StringUtils.isNotBlank(id)) {
            if (QuestionsAnswersQueryDTO.QUESTIONS_NUM.equals(questionsAndAnswers)) {
                o = answersService.find(id);
            } else {
                o = questionsAnswersService.find(id);
            }
        }
        model.addAttribute("questionsAnswers", o);
        model.addAttribute("questionsAndAnswers", questionsAndAnswers);
        model.addAttribute(Constants.MENU_NAME, Constants.MANAGEMENT);
        return "user/information/edit/management_edit";
    }


    /**
     * @Ceator:liuYI
     * @Describe:问答管理回复操作
     */
    @RequestMapping("/management/reply")
    @ResponseBody
    public AjaxResult managementReply(HttpServletRequest request) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);
        try {
            String id = request.getParameter("id");
            String text = request.getParameter("text");
            if (StringUtils.isNotBlank(id)) {
//                咨询表更改
                QuestionsAnswers questionsAnswers = questionsAnswersService.find(id);
                questionsAnswers.setReplyDate(new Date());
                questionsAnswers.setState("1");
                questionsAnswers.setReply(text);
                questionsAnswersService.update(questionsAnswers);
//                回复表添加
                Answers answers = new Answers();
                answers.setAuditFlag(Answers.AUDIT_FLAG_FAIL);
                answers.setQuestionsAnswersId(questionsAnswers.getId());
                answers.setReplyDate(new Date());
                answers.setUid("0");
                answers.setReply(text);
                answers.setText(questionsAnswers.getText());
                answers.setQueUid(questionsAnswers.getUid());
                answersService.save(answers);
            }
            ajaxResult.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ajaxResult;
    }

    @Autowired
    private CnaaApplyForService cnaaApplyForService;

    /**
     * @Ceator:liuYI
     * @Describe:cnaa入会申请列表展示
     */
    @RequestMapping("/cnaaApplyFor")
    public String cnaaApplyFor(HttpServletRequest request, Model model) {
        String currentPageStr = request.getParameter("currentPage");//当前页
        String pageSizeStr = request.getParameter("pageSize");//每页显示条数
        String level = request.getParameter("level");//等级
        String auditFlag = request.getParameter("auditFlag");//审核字段 0->未处理 1->处理
        int currentPage = 1;
        int pageSize = 10;
        if (StringUtils.isNotBlank(currentPageStr)) {
            currentPage = Integer.parseInt(currentPageStr);
        }
        if (StringUtils.isNotBlank(pageSizeStr)) {
            pageSize = Integer.parseInt(pageSizeStr);
        }
        CnaaApplyForQueryDTO cnaaApplyForQueryDTO = new CnaaApplyForQueryDTO();
        cnaaApplyForQueryDTO.setCurrentPage(currentPage);
        cnaaApplyForQueryDTO.setPageSize(pageSize);
        cnaaApplyForQueryDTO.setLevel(level);
        cnaaApplyForQueryDTO.setAuditFlag(auditFlag);
        PageModel<CnaaApplyFor> page = cnaaApplyForService.queryCnaaApplyForPage(cnaaApplyForQueryDTO);
        model.addAttribute("page", page);
        model.addAttribute("pageSize", pageSize);
        model.addAttribute("cnaaApplyForQueryDTO", cnaaApplyForQueryDTO);
        model.addAttribute(Constants.MENU_NAME, Constants.CNAA_APPLY_FOR);
        return "user/information/cnaa_apply_for";
    }

    /**
     * @Ceator:liuYI
     * @Describe:cnaa申请删除操作
     */
    @RequestMapping("/cnaaApplyFor/delete")
    @ResponseBody
    public AjaxResult cnaaApplyForDelete(HttpServletRequest request) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);
        String id = request.getParameter("id");
        String deleteFlag = request.getParameter("deleteFlag");
        if (StringUtils.isNotBlank(id)) {
            CnaaApplyFor cnaaApplyFor = cnaaApplyForService.find(id);
            cnaaApplyFor.setDeleteFlag(deleteFlag);
            cnaaApplyForService.update(cnaaApplyFor);
            ajaxResult.setSuccess(true);
        }
        return ajaxResult;
    }

    /**
     * @Ceator:liuYI
     * @Describe:后台获批企业数据置顶
     */
    @RequestMapping("/cnaaApplyFor/stick")
    @ResponseBody
    public AjaxResult cnaaApplyForStick(HttpServletRequest request) {
        AjaxResult ajaxResult = new AjaxResult();
        String id = request.getParameter("id");
        CnaaApplyFor cnaaApplyFor = cnaaApplyForService.findMaxSort();
        int sort = cnaaApplyFor.getSort();
        cnaaApplyFor = cnaaApplyForService.find(id);
        sort++;
        cnaaApplyFor.setSort(sort);
        cnaaApplyForService.update(cnaaApplyFor);
        ajaxResult.setSuccess(true);
        return ajaxResult;
    }

    /**
     * @Ceator:liuYI
     * @Describe:后台获批企业添加/编辑
     */
    @RequestMapping("/cnaaApplyFor/edit")
    public String cnaaApplyForEdit(HttpServletRequest request, Model model) {
        String id = request.getParameter("id");
        CnaaApplyFor cnaaApplyFor = null;
        if (StringUtils.isNotBlank(id)) {
            cnaaApplyFor = cnaaApplyForService.find(id);
        }
        model.addAttribute("cnaaApplyFor", cnaaApplyFor);
        model.addAttribute(Constants.MENU_NAME, Constants.CNAA_APPLY_FOR);
        return "user/information/edit/cnaa_apply_for";
    }

    /**
     * @Ceator:liuYI
     * @Describe:后台管理添加获批企业
     */
    @RequestMapping("/cnaaApplyFor/save")
    @ResponseBody
    public AjaxResult saveCnaaApplyFor(HttpServletRequest request) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);
        String id = request.getParameter("id");//主键id
        String uid = request.getParameter("uid");//用户id
        String level = request.getParameter("level");//申请级别 0->1级;1->2级;2->3级
        String companyName = request.getParameter("companyName");//企业名称
        String linkman = request.getParameter("linkman");//联系人
        String phone = request.getParameter("phone");//联系人电话
        String deleteFlag = request.getParameter("deleteFlag");//是否封存
        if (StringUtils.isNotBlank(id)) {//修改
            CnaaApplyFor cnaaApplyFor = cnaaApplyForService.find(id);
            cnaaApplyFor.setCompanyName(companyName);
            cnaaApplyFor.setLinkman(linkman);
            cnaaApplyFor.setPhone(phone);
            cnaaApplyFor.setLevel(level);
            cnaaApplyFor.setAuditFlag(deleteFlag);
            cnaaApplyForService.update(cnaaApplyFor);
            ajaxResult.setSuccess(true);
        } else {            //添加
            CnaaApplyFor cnaaApplyFor = new CnaaApplyFor();
            cnaaApplyFor.setLevel(level);
            cnaaApplyFor.setUid(uid);
            cnaaApplyFor.setSort(0);
            cnaaApplyFor.setCompanyName(companyName);
            cnaaApplyFor.setLinkman(linkman);
            cnaaApplyFor.setPhone(phone);
            cnaaApplyFor.setAuditFlag(deleteFlag);
            cnaaApplyForService.save(cnaaApplyFor);
            ajaxResult.setSuccess(true);
        }
        return ajaxResult;
    }

    /**
     * @Ceator:liuYI
     * @Describe:cnaa入会申请处理操作
     */
    @RequestMapping("/cnaaApplyFor/audit_flag")
    @ResponseBody
    public AjaxResult cnaaApplyForAuditFlag(HttpServletRequest request) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);
        try {
            String id = request.getParameter("id");
            if (StringUtils.isNotBlank(id)) {
                String[] split = id.split(",");
                Arrays.stream(split).forEach(t -> {
                    CnaaApplyFor cnaaApplyFor = cnaaApplyForService.find(t);
                    cnaaApplyFor.setAuditFlag("1");
                    cnaaApplyForService.update(cnaaApplyFor);
                });
            }
            ajaxResult.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ajaxResult;
    }

    @Autowired
    private CompanyService companyService;

    /**
     * @Ceator:liuYI
     * @Describe:公司信息列表
     */
    @RequestMapping("/company/list")
    public String companyList(HttpServletRequest request, Model model) {
        String currentPageStr = request.getParameter("currentPage");//当前页
        String pageSizeStr = request.getParameter("pageSize");//每页显示条数
        String auditFlag = request.getParameter("auditFlag");//审核字段 0->未处理 1->处理
        int currentPage = 1;
        int pageSize = 10;
        if (StringUtils.isNotBlank(currentPageStr)) {
            currentPage = Integer.parseInt(currentPageStr);
        }
        if (StringUtils.isNotBlank(pageSizeStr)) {
            pageSize = Integer.parseInt(pageSizeStr);
        }
//        Company
        CompanyQueryDTO dto = new CompanyQueryDTO();
        dto.setPageSize(pageSize);
        dto.setCurrentPage(currentPage);
        dto.setAuditFlag(auditFlag);
        PageModel<Company> page = companyService.queryCompanyPage(dto);
        model.addAttribute("page", page);
        model.addAttribute("pageSize", pageSize);
        model.addAttribute("dto", dto);
        model.addAttribute(Constants.MENU_NAME, Constants.COMPANY_MESSAGE);
        return "user/information/company";
    }

    /**
     * @Ceator:liuYI
     * @Describe:公司信息后台审核操作
     */
    @RequestMapping("/company/auditFlag")
    @ResponseBody
    public AjaxResult companyAuditFlag(HttpServletRequest request) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);
        try {
            String id = request.getParameter("id");
            String auditFlag = request.getParameter("auditFlag");
            if (StringUtils.isNotBlank(id)) {
                Company company = companyService.find(id);
                company.setAuditFlag(auditFlag);
                companyService.update(company);
            }
            ajaxResult.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return ajaxResult;
    }

    /**
     * @Ceator:liuYI
     * @Describe:公司信息详情展示
     */
    @RequestMapping("/company/edit")
    public String companyEdit(HttpServletRequest request, Model model) {
        String id = request.getParameter("id");
        Company company = null;
        if (StringUtils.isNotBlank(id)) {
            company = companyService.find(id);
        }
        model.addAttribute("company", company);
        model.addAttribute(Constants.MENU_NAME, Constants.COMPANY_MESSAGE);
        return "user/information/edit/company_edit";
    }

    /**
     * @Ceator:liuYI
     * @Describe:平台回复跳转编辑
     */
    @RequestMapping("/reply")
    public String reply(HttpServletRequest request, Model model) {
        String id = request.getParameter("id");
        String url = request.getParameter("url");
        model.addAttribute("id", id);
        model.addAttribute("url", url);
        return "user/information/edit/reply";
    }


}
